package com.example.demoserver.controller;

import com.example.demoserver.entity.HousePartstore;
import com.example.demoserver.entity.HouseProduct;
import com.example.demoserver.service.impl.HousePartstoreServiceImpl;
import com.example.demoserver.service.impl.HouseProductServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/product")
@RequiredArgsConstructor
@Component
public class productController {
    private final HouseProductServiceImpl houseProductService;

    @PostMapping("/insertpro")
    public boolean InsertPro(@RequestBody List<HouseProduct> houseProducts) {
        boolean bol = houseProductService.saveBatch(houseProducts);
        return bol;
    }

    @GetMapping("/selectpro")
    public List<HouseProduct> selectPro(Integer type) {
        List<HouseProduct> list = houseProductService.list();
        List<HouseProduct> list1 = new ArrayList<>();
        if (type == 1) {
            for (HouseProduct h : list) {
                if (h.getProductid() != null) {
                    list1.add(h);
                }
            }
        } else {
            for (HouseProduct h : list) {
                if (h.getProductid() == null) {
                    list1.add(h);
                }
            }
        }

        return list1;
    }
}
